package com.fyzk.view.myview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;

public class MyWebView extends WebView{
	
	private ProgressBar progressBar;
	private boolean mPreventParentTouch;

	public MyWebView(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		progressBar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
		progressBar.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 10, 0, 0));
		
		this.addView(progressBar);
		
		setWebChromeClient(new WebChromeClient1());
	
	}

	@Override
	protected void onScrollChanged(int l, int t, int oldl, int oldt) {

		LayoutParams lp = (LayoutParams) progressBar.getLayoutParams();
		lp.x = l;
		lp.y = t;
		progressBar.setLayoutParams(lp);
		super.onScrollChanged(l, t, oldl, oldt);
	}
	
	public class WebChromeClient1 extends WebChromeClient{
		@Override
		public void onProgressChanged(WebView view, int newProgress) {

			if (newProgress == 100) {
				progressBar.setVisibility(View.GONE);
			}else {
				if (progressBar.getVisibility() == View.GONE) {
					progressBar.setVisibility(View.VISIBLE);
				}
				
				progressBar.setProgress(newProgress);
			}
			super.onProgressChanged(view, newProgress);
		}
	}
	
}
